package model.domain;

import java.util.List;

import model.advertisers.Advertiser;

public class Advert {

	private double id;
	private String date;
	private String name;
	private String price;
	private String currency;
	private String category;
	private String town;
	private String postalCode;

	private String department;

	private String hyperlinkDetail;
	private String hyperlinkPicture;

	private String hyperlinkPictureHD;

	private String detail;

	private Owner owner;

	private String urlContact;

	private Advertiser advertiser;

	public String toString() {

		String result = "advertiser: " + this.getAdvertiser() + "\nid: "
				+ this.getId() + "\ndate: " + this.getDate() + "\nname: "
				+ this.getName() + "\nhyperlinkPicture: "
				+ this.getHyperlinkPicture() + "\nhyperlink: "
				+ this.getHyperlinkDetail() + "\nPrix: " + this.getPrice()
				+ "\nDepart: " + this.getDepartment() + "\nVille: "
				+ this.getTown() + "\nCategory: " + this.getCategory();

		if (getDetail() != null) {
			String detail = this.getDetail();
			String postalCode = this.getPostalCode();
			String ownerName = this.getOwner().getName();
			String urlContact = this.getUrlContact();
			String pictureHD = this.getHyperlinkPictureHD();

			String phoneNumber = null;
			if (this.getOwner().getPhoneNumber() != null) {
				phoneNumber = this.getOwner().getPhoneNumber().toString();
			}

			result = result + "\npostalCode: " + postalCode + "\nownerName: "
					+ ownerName + "\nphoneNumber: " + phoneNumber
					+ "\nurlContact: " + urlContact + "\npictureHD: "
					+ pictureHD + " \ndetail: " + detail;
		}

		result = result
				+ "\n--------------------------------------------------------";

		return result;

	}

	public void reparseAllAtributes() {

		this.setName(this.getAdvertiser().reparse(this.getName()));
		this.setDepartment(this.getAdvertiser().reparse(this.getDepartment()));
		this.setTown(this.getAdvertiser().reparse(this.getTown()));
		this.setCategory(this.getAdvertiser().reparse(this.getCategory()));

	}

	public static Advert findById(List<Advert> adverts, double id) {
		for (Advert advert : adverts) {
			if (advert.getId() == id) {
				return advert;
			}
		}
		return null;
	}

	public double getId() {
		return id;
	}

	public void setId(double id) {
		this.id = id;
	}

	public String getDate() {
		return date;
	}

	public void setDate(String date) {
		this.date = date;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getName() {
		return name;
	}

	public void setCurrency(String currency) {
		this.currency = currency;
	}

	public String getCurrency() {
		return currency;
	}

	public void setHyperlinkDetail(String hyperlinkDetail) {
		this.hyperlinkDetail = hyperlinkDetail;
	}

	public String getHyperlinkDetail() {
		return hyperlinkDetail;
	}

	public void setHyperlinkPicture(String hyperlinkPicture) {
		this.hyperlinkPicture = hyperlinkPicture;
	}

	public String getHyperlinkPicture() {
		return hyperlinkPicture;
	}

	public void setDepartment(String department) {
		this.department = department;
	}

	public String getDepartment() {
		return department;
	}

	public void setTown(String town) {
		this.town = town;
	}

	public String getTown() {
		return town;
	}

	public void setCategory(String category) {
		this.category = category;
	}

	public String getCategory() {
		return category;
	}

	public void setPrice(String price) {
		this.price = price;
	}

	public String getPrice() {
		return price;
	}

	public Advertiser getAdvertiser() {
		return advertiser;
	}

	public void setAdvertiser(Advertiser advertiser) {
		this.advertiser = advertiser;
	}

	public Advert getMoreDetail() {
		return this.getAdvertiser().findDetails(this);
	}

	public String getDetail() {

		return detail;
	}

	public void setDetail(String detail) {
		this.detail = detail;
	}

	public Owner getOwner() {
		return owner;
	}

	public void setOwner(Owner owner) {
		this.owner = owner;
	}

	public String getUrlContact() {
		return urlContact;
	}

	public void setUrlContact(String urlContact) {
		this.urlContact = urlContact;
	}

	public String getPostalCode() {
		return postalCode;
	}

	public void setPostalCode(String postalCode) {
		this.postalCode = postalCode;
	}

	public String getHyperlinkPictureHD() {
		return hyperlinkPictureHD;
	}

	public void setHyperlinkPictureHD(String hyperlinkPictureHD) {
		this.hyperlinkPictureHD = hyperlinkPictureHD;
	}

}
